package com.magist.manage.web.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.magist.core.constants.Deleted;
import com.magist.core.entity.Page;
import com.magist.core.exception.BusinessException;
import com.magist.core.service.SimpleServiceImpl;
import com.magist.manage.web.dao.SysAuthMapper;
import com.magist.manage.web.entity.SysAuth;
import com.magist.manage.web.service.SysAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class SysAuthServiceImpl extends SimpleServiceImpl<SysAuth> implements SysAuthService {

	@Autowired
	private SysAuthMapper sysAuthMapper;

	@Override
	public void addAuth(SysAuth sysAuth) {
		Assert.hasLength(sysAuth.getName(),"名称为空");
		Assert.hasLength(sysAuth.getUrl(),"地址不能为空");
		SysAuth param = new SysAuth();
		param.setDeleted(Deleted.NO_STR);
		param.setName(sysAuth.getName());
		if(this.find(param).size()>0){
			throw new BusinessException("名称重复");
		}
		param.setName(null);
		param.setUrl(sysAuth.getUrl());
		if(this.find(param).size()>0){
			throw new BusinessException("URL重复");
		}
		this.insert(sysAuth);
	}
}